//! 定义武将性别信息

/// 武将性别
#[derive(Debug, Clone, PartialEq)]
pub enum Gender {
    /// 未知类型，一般表示出错
    Unknown,

    /// 男性
    Male,

    /// 女性
    Female,
}

impl Default for Gender {
    fn default() -> Self {
        Self::Unknown
    }
}

impl std::fmt::Display for Gender {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Gender::Unknown => "Unknown",
                Gender::Male => "男",
                Gender::Female => "女",
            }
        )
    }
}

impl TryFrom<&str> for Gender {
    type Error = crate::ParseStrError;

    fn try_from(text: &str) -> Result<Gender, Self::Error> {
        match text {
            "男" | "男性" | "MALE" | "Male" | "male" | "M" | "m" => Ok(Self::Male),

            "女" | "女性" | "FEMALE" | "Female" | "female" | "F" | "f" => Ok(Self::Female),

            _ => Err(crate::ParseStrError::new(crate::ParseType::Gender, text)),
        }
    }
}
